﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using imaginecup.information;
using imaginecup.objectManager;
using imaginecup.util;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.sprite;
using Imaginecup.sprite.changeSourceSize;
using Imaginecup.gameState.malaria.component.entity;
using Microsoft.Xna.Framework;

namespace Imaginecup.gameState.malaria.component.etc
{
    public class CmpProgressBar : MalariaStateBaseComponent, ICmpEntity , ISourceInfoClass , IRelativeSourceInfoClass
    {
        private EntityInfo m_Info;
        private EntityInfo m_SourceInfo;

        private ICmpChar m_CharEntity;

        private int TextureBarSizeX;
        private int TextureBarSizeY;


        public CmpProgressBar(GObjectID a_GID, ObjectManager ObjMan , ICmpChar cmpChar)
            : base(a_GID, ObjMan, ComponentTypeID.CID_ETC)
        {
            ChangeSourceSizeSprite baseSprite = new ChangeSourceSizeSprite();
            baseSprite.SetSourceInfoClass( this );
            baseSprite.SetTextureName("ProgressBar");

            RelativeSprite upSprite = new RelativeSprite();
            upSprite.SetRelativeInfo( this );
            upSprite.SetTextureName("ProgressBar");

            CompositeSprite sprite = new CompositeSprite();
            sprite.AddSprite(baseSprite);
            sprite.AddSprite(upSprite);

            ICmpRender render = new CmpDefaultRender(a_GID , ObjMan , sprite , ComponentTypeID.CID_RENDER_PROGRESSBAR);
            m_ObjectMan.AddComponent(render);

            m_Info.mSize.X = 60;
            m_Info.mSize.Y = 10;

            TextureBarSizeX = 100;
            TextureBarSizeY = 15;

            m_CharEntity = cmpChar;
        }

        public EntityInfo GetRelativeSource()
        {
            int demagePercent = m_CharEntity.GetDemage();

            m_SourceInfo.mPosition.X = 0;
            m_SourceInfo.mPosition.Y = 0;
            m_SourceInfo.mSize.X = TextureBarSizeX - (int)(demagePercent / 100.0 * TextureBarSizeX);
            m_SourceInfo.mSize.Y = TextureBarSizeY;

            return m_SourceInfo;
        }
       

        public Vector2 GetOffsetPos()
        {
            return Vector2.Zero;
        }

        public Vector2 GetOffsetSize()
        {
            int demagePercent = m_CharEntity.GetDemage();

            float offsetX = -(demagePercent / 100.0f * m_Info.mSize.X);
            Vector2 offset = new Vector2(offsetX, 0);
            return offset;
        }

        public EntityInfo GetSourceInfo()
        {
            m_SourceInfo.mPosition.X = TextureBarSizeX;
            m_SourceInfo.mPosition.Y = 0;
            m_SourceInfo.mSize.X = TextureBarSizeX;
            m_SourceInfo.mSize.Y = TextureBarSizeY;

            return m_SourceInfo;
        }

        public Object GetEntityInfo()
        {
            EntityInfo charInfo = (EntityInfo)m_CharEntity.GetEntityInfo();

            int CenterX = (int)(charInfo.mPosition.X + charInfo.mSize.X / 2);
            m_Info.mPosition.X = CenterX - m_Info.mSize.X / 2;

            m_Info.mPosition.Y = charInfo.mPosition.Y - 10;

            return m_Info;
        }

        public void Update(GameTime gameTime)
        {

            throw new NotImplementedException();
        }

        public void SetEntityInfo(object a_Info)
        {
            throw new NotImplementedException();
        }
    }

     
}
